package com.bbzn.user.client.utils;

import com.bbzn.user.client.enums.ResultEnum;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

@Getter
@Setter
@ToString
@ApiModel(value="接口对象", description="接口返回信息")
public class BaseResponse<T> {

	/**
	 * 返回码
	 */
	@ApiModelProperty(value = "返回码",example = "0")
	private Integer code;

	/**
	 * 消息(最好用简写，不占用宽带)
	 */
	@ApiModelProperty(value = "消息(最好用简写，不占用宽带)",example = "登录成功")
	private String msg;

	/**
	 * 数据
	 */
	@ApiModelProperty(value = "数据",example = "[{}]")
	private T data;

	public BaseResponse() {

	}

	public BaseResponse(Integer code, String msg) {
		super();
		this.code = code;
		this.msg = msg;
	}

	public BaseResponse(Integer code, String msg, T data) {
		super();
		this.code = code;
		this.msg = msg;
		this.data = data;
	}

	/**
	 * 未登录返回结果
	 */
	public static <T> BaseResponse<T> unauthorized(T data) {
		return new BaseResponse<T>(ResultEnum.UNAUTHORIZED.getCode(), ResultEnum.UNAUTHORIZED.getMsg(), data);
	}

	/**
	 * 未授权返回结果
	 */
	public static <T> BaseResponse<T> forbidden(T data) {
		return new BaseResponse<T>(ResultEnum.FORBIDDEN.getCode(), ResultEnum.FORBIDDEN.getMsg(), data);
	}


}